
public class Vector {

	private double vx;
	private double vy;
	private double vz;
	
	public Vector(double x, double y, double z ){
		this.vx=x;
		this.vy=y;
		this.vz=z;
	}
	
	public double getvx(){
		return this.vx;
	}
	
	public double getvy(){
		return this.vy;
	}
	
	public double getvz(){
		return this.vz;
	}
	
	public void setvx(double newvx){
		this.vx = newvx;
	}
	
	public void setvy(double newvy){
		this.vy = newvy;
	}
	
	public void setvz(double newvz){
		this.vz = newvz;
	}
	
	
	public Vector addVectors(Vector other){
		return new Vector(vx+other.getvx(), vy+other.getvy(), vz+other.getvz());
	}
	
	public Vector subtructVector(Vector other){
		return new Vector(vx-other.getvx(),
						  vy-other.getvy(),
						  vz-other.getvz());
	}
	
	public double dotProduct(Vector other){
		return (vx*other.getvx() + vy*other.getvy() + vz*other.getvz());
		
	}
	
	
	
	public Vector multiplyVectorByScalar(double scalar){
		
		return new Vector(vx*scalar,vy*scalar,vz*scalar);
	}
	
	
	public Vector crossProduct(Vector other){
		
		return new Vector(vy*other.getvz() - vz*other.getvy(),
						  vz*other.getvx() - vx*other.getvz(),
						  vx*other.getvy() - vy*other.getvx());
		
	}
	
	public Vector multiplyMatrixByVector(double[][] matrix){
		if(matrix[0].length != 3 || matrix.length != 3){
			System.out.println("this matrix is not the correct size");
			return null;
		}
		
		Vector result = new Vector(0, 0, 0);
		double x = vx;
		double y = vy;
		double z = vz;
		result.setvx(matrix[0][0]*x + matrix[0][1]*y + matrix[0][2]*z);
		result.setvy(matrix[1][0]*x + matrix[1][1]*y + matrix[1][2]*z);
		result.setvz(matrix[2][0]*x + matrix[2][1]*y + matrix[2][2]*z);
		
		return result;
		
	}
	
	public double norm(){
		return Math.sqrt(vx*vx+vy*vy+vz*vz);
	}
	
	public Vector normalizedVector(){
		Vector newVector=new Vector(0,0,0);
		double norm=this.norm();
		if(norm == 0){
			return this;
		}else{
			newVector.setvx(vx/norm);
			newVector.setvy(vy/norm);
			newVector.setvz(vz/norm);	
			return newVector;
		}	
	}
	
	public Vector addScalar(double scalar){
		return new Vector(vx+scalar,vy+scalar,vz+scalar);
	}
	
	
	public double distance(Vector other) {
		double result = 0;
		
		result += Math.pow(vx - other.getvx(), 2) + Math.pow(vy - other.getvy(), 2) + Math.pow(vz - other.getvz(), 2);
		
		return Math.sqrt(result);
	}
	
	
	
	@Override
    public String toString() {
        return "<"+vx+","+vy+","+vz+">";
    }
}
